package arkham.net;

public class NetworkUtils {

	public static final byte[] intToByteArray(int value) {
		return new byte[] {
				(byte)(value >>> 24),
				(byte)(value >>> 16),
				(byte)(value >>> 8),
				(byte)value};
	}

	public static final int byteArrayToInt(byte[] b) {
		return byteArrayToInt(b, 0); 
	}
	
	public static final int byteArrayToInt(byte[] b, int off) {
		int val = 0;
		for (int i = off; i < off + 4; i++)
		{
			val <<= 8;
			int absval = (b[i] >= 0) ? b[i] : 256 + b[i];
			val += absval;
		}
		
		return val; 
	}
	
}
